<?php

class Kal_Banners_Block_Manage_Banners_Edit_Tab_Options extends Mage_Adminhtml_Block_Widget_Form
{
	protected function _prepareForm()
	{
		$form = new Varien_Data_Form();
		$this->setForm($form);
		$fieldset = $form->addFieldset('banners_form', array('legend'=>Mage::helper('banners')->__('Layout Order Information')));
		
		
		$id= $this->getRequest()->getParam('id');
		$post = Mage::getModel('banners/post')->load($id);
		
		$categories = array();
	  	$collection = Mage::getModel('features/cat')->getCollection()->setOrder('sort_order', 'asc');
		foreach ($collection as $cat) {
			$categories[] = ( array(
				'label' => (string)$cat->getTitle(),
				'value' => $cat->getCatId()
				));
		}
		
	  	$fieldset->addField('types', 'multiselect', array(
                'name'      => 'types[]',
                'label'     => Mage::helper('banners')->__('Features'),
                'title'     => Mage::helper('banners')->__('Features'),
                'required'  => true,
                'values'    => $categories,
     	));
        
     	$array = split(',',$post->getTypes());

     	for ($i=0;$i<count($array);$i++)
     	{
     		$cat= Mage::getModel('features/cat')->load($array[$i]);
     		
  			$field = $cat->getIdentifier();
     		$fieldname = $cat->getTitle();
     		
     		$fieldset->addField('order_'.$field, 'text', array(
			'name' => 'order_'.$field,
			'label' => Mage::helper('banners')->__('Order In '.$fieldname),
			'title' => Mage::helper('banners')->__('Order In '.$fieldname),
			'style' => 'width: 520px;',
			));
		
     	}

		if ( Mage::getSingleton('adminhtml/session')->getBannersData() )
		{
			$form->setValues(Mage::getSingleton('adminhtml/session')->getBannersData());
			Mage::getSingleton('adminhtml/session')->setBannersData(null);
			} elseif ( Mage::registry('banners_data') ) 
			{
				$form->setValues(Mage::registry('banners_data')->getData());
			}
			return parent::_prepareForm();
		}
	}